from gdmap_caps import *
from appium.webdriver.common.appiumby import By
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.multi_action import MultiAction
dr = gaode_map()
dr.find_element(By.ID, 'com.autonavi.minimap:id/agree').click()   #同意
sleep(1)
dr.find_element(By.ID, 'com.autonavi.minimap:id/enter_amap').click()  #进入地图
sleep(1)
dr.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button').click()
sleep(1)
dr.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button').click()
sleep(1)
dr.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button').click()
sleep(1)
dr.find_element(By.ID, 'com.autonavi.minimap:id/map_widget_container').click()
sleep(1)

def smaller(dr):
    x = dr.get_window_size()['width']
    y = dr.get_window_size()['height']
    t1 = TouchAction(dr)
    t2 = TouchAction(dr)
    t1.press(x=0.2 * x, y=0.2 * y).wait(1000).move_to(x=0.4 * x, y=0.4 * y).wait(1000).release()
    t2.press(x=0.8 * x, y=0.8 * y).wait(1000).move_to(x=0.6 * x, y=0.6 * y).wait(1000).release()

    m = MultiAction(dr)
    m.add(t1, t2)
    m.perform()


def bigger(driver):
    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']
    t1 = TouchAction(driver)
    t2 = TouchAction(driver)
    t1.press(x=0.4 * x, y=0.4 * y).wait(1000).move_to(x=0.2 * x, y=0.2 * y).wait(1000).release()
    t2.press(x=0.6 * x, y=0.6 * y).wait(1000).move_to(x=0.8 * x, y=0.8 * y).wait(1000).release()

    m = MultiAction(driver)
    m.add(t1, t2)
    m.perform()

if __name__ == '__main__':
    smaller(dr)
    bigger(dr)